﻿#region Header

/*
    This file is part of nDoctor Light

    NDoctor is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    NDoctor is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with NDoctor.  If not, see <http://www.gnu.org/licenses/>.
*/

#endregion Header

namespace Probel.Ldoc.ViewModels.Controls
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Input;

    using Probel.Ldoc.Services.Dto;
    using Probel.Ldoc.Services.Services;
    using Probel.Ldoc.ViewModels.Pages;
    using Probel.Ldoc.ViewModels.Properties;
    using Probel.Ldoc.ViewModels.ToolBoxes;
    using Probel.Mvvm.DataBinding;

    internal class SpecialisationPopupViewModel : BaseViewModel, ITextPopupViewModel
    {
        #region Fields

        private readonly RelayCommand createCommand;
        private readonly CreateDoctorViewModel ParentViewModel;
        private readonly IPatientService Service;

        private string itemName;

        #endregion Fields

        #region Constructors

        public SpecialisationPopupViewModel(CreateDoctorViewModel parent, IErrorService errorService, IPatientService service, bool isAsync = true)
            : base(errorService, isAsync)
        {
            this.Service = service;
            this.ParentViewModel = parent;

            this.createCommand = new RelayCommand(this.Create, this.CanCreate);
        }

        #endregion Constructors

        #region Properties

        public ICommand CreateCommand
        {
            get { return this.createCommand; }
        }

        public string ItemName
        {
            get { return this.itemName; }
            set
            {
                this.itemName = value;
                this.OnPropertyChanged(() => ItemName);
            }
        }

        public string Watermark
        {
            get { return Messages.Watermark_NewSpecialisation; }
        }

        #endregion Properties

        #region Methods

        private bool CanCreate()
        {
            return !string.IsNullOrWhiteSpace(this.ItemName);
        }

        private void Create()
        {
            var specialisation = new SpecialisationDto() { Name = this.ItemName };

            this.Service.Create(specialisation);
            this.ParentViewModel.Initialise();
        }

        #endregion Methods
    }
}